//
//  MHFeedBackController.m
//  M-Saler
//
//  Created by Teresa on 2020/5/21.
//  Copyright © 2020 Teresa. All rights reserved.
//

#import "MHFeedBackController.h"
#import "MHFeedbackRequest.h"

@interface MHFeedBackController ()<UITextFieldDelegate,UITextViewDelegate>

@property (weak, nonatomic) IBOutlet UITextField *textField;
@property (weak, nonatomic) IBOutlet UITextView *textView;
@property (weak, nonatomic) IBOutlet UILabel *placeholderLabel;

@end

@implementation MHFeedBackController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"意见反馈";
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self configNavBarRed];
}

- (IBAction)sendFeedBack:(id)sender {
    if (self.textView.text.length > 0 && self.textField.text.length > 0) {
        MHFeedbackRequest *req = [MHFeedbackRequest new];
        req.salesman_id = [MHUserModel userModel].theID;
        req.title = self.textField.text;
        req.content = self.textView.text;
        BLOCKSELF;
        [req asyncRequestWithsuccessHandler:^(BaseResponse *response) {
            [[HUDHelper sharedInstance]tipMessage:response.message delay:1 completion:^{
                [blockSelf.navigationController popViewControllerAnimated:YES];
            }];
        } failHandler:^(BaseResponse *response) {
             [[HUDHelper sharedInstance]tipMessage:response.message];
        }];
    }else{
        [[HUDHelper sharedInstance]tipMessage:@"反馈标题和内容不能为空" delay: 1];
    }
}

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
    NSString *newStr = [textView.text stringByReplacingCharactersInRange:range withString:text];
    self.placeholderLabel.hidden = newStr.length > 0 ? YES : NO;
    if (newStr.length > 300) {
        [[HUDHelper sharedInstance]tipMessage:@"反馈内容不能超过300字" delay: 1];
        return NO;
    }
    return YES;
}
@end
